package com.mvd.app.ac_wenzhou;

import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.google.gson.Gson;
import com.kongzue.dialog.interfaces.OnMenuItemClickListener;
import com.kongzue.dialog.util.TextInfo;
import com.kongzue.dialog.v3.BottomMenu;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.lzy.okgo.request.base.Request;
import com.mvd.app.R;
import com.mvd.app.activity.BaseActivity;
import com.mvd.app.application.BaseApplication;
import com.mvd.app.commons.CommonUtils;
import com.mvd.app.commons.DateUtil;
import com.mvd.app.commons.PDALogUtils;
import com.mvd.app.commons.SharedPreferencesUtils;
import com.mvd.app.commons.UtilsLog;
import com.mvd.app.model.HuanBaoDataModel;
import com.mvd.app.model.HuanBaoItemModel;
import com.mvd.app.model.HuanBaoModel;
import com.mvd.app.model.ResultModel;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.iwgang.countuptime.CountupView;

import static com.mvd.app.commons.Constants.HUANBAO_ITEMS;

/**
 * @author Administrator
 * @version V1.0
 * @Title: HuanBaoItemActivity
 * @Package com.mvd.app.ac_wenzhou
 * @Description: 环保项目  17项
 * @date 2020-07-16 14:31
 **/

public class HuanBaoItemActivity extends BaseActivity {
    //region
    @BindView(R.id.ac_huan_h_16)
    TextView acHuanH16;
    @BindView(R.id.ac_huan_h_21)
    TextView acHuanH21;
    @BindView(R.id.ac_huan_h_18)
    TextView acHuanH18;
    @BindView(R.id.ac_huan_tongfeng)
    TextView acHuanTongfeng;
    @BindView(R.id.ac_huan_shifou_ranyou_zhengfa_kongzhi_zhuangzhi)
    TextView acHuanShifouRanyouZhengfaKongzhiZhuangzhi;
    @BindView(R.id.ac_huan_h_19)
    TextView acHuanH19;
    @BindView(R.id.ac_huan_h_20)
    TextView acHuanH20;
    @BindView(R.id.ac_huan_jin_paiqi)
    TextView acHuanJinPaiqi;
    @BindView(R.id.ac_huan_h_22)
    TextView acHuanH22;
    @BindView(R.id.ac_huan_h_14)
    TextView acHuanH14;
    @BindView(R.id.ac_huan_h_23)
    TextView acHuanH23;
    @BindView(R.id.ac_huan_h_24)
    TextView acHuanH24;
    @BindView(R.id.ac_huan_h_25)
    TextView acHuanH25;
    @BindView(R.id.ac_huan_h_26)
    TextView acHuanH26;
    @BindView(R.id.ac_huan_h_27)
    TextView acHuanH27;
    @BindView(R.id.ac_huan_h_28)
    TextView acHuanH28;
    @BindView(R.id.ac_huan_shifou_diankongbeng)
    TextView acHuanShifouDiankongbeng;
    @BindView(R.id.title_btn_left)
    ImageButton titleBtnLeft;
    @BindView(R.id.title_btn_left_txt)
    Button titleBtnLeftTxt;
    @BindView(R.id.title_txt)
    TextView titleTxt;
    @BindView(R.id.iv_headtip)
    ImageView ivHeadtip;
    @BindView(R.id.title_btn_right_txt)
    Button titleBtnRightTxt;
    @BindView(R.id.title_btn_right)
    ImageButton titleBtnRight;
    @BindView(R.id.include_huan_h_1)
    TextView includeHuanH1;
    @BindView(R.id.include_huan_h_2)
    TextView includeHuanH2;
    @BindView(R.id.include_huan_h_3)
    TextView includeHuanH3;
    @BindView(R.id.include_huan_h_10)
    TextView includeHuanH10;
    @BindView(R.id.include_huan_h_11)
    TextView includeHuanH11;
    @BindView(R.id.include_huan_h_12)
    TextView includeHuanH12;
    @BindView(R.id.include_huan_h_13)
    TextView includeHuanH13;
    @BindView(R.id.include_huan_h_15)
    TextView includeHuanH15;
    @BindView(R.id.include_huan_youxianggai)
    TextView includeHuanYouxianggai;
    @BindView(R.id.ll_ac_huan_shifou_diankongbeng_tv)
    TextView llAcHuanShifouDiankongbengTv;
    @BindView(R.id.ll_ac_huan_shifou_diankongbeng)
    LinearLayout llAcHuanShifouDiankongbeng;
    @BindView(R.id.ac_huanbao_item_CountupViewTest3)
    CountupView acHuanbaoItemCountupViewTest3;
    @BindView(R.id.ac_huanbao_item_time_time)
    TextView acHuanbaoItemTimeTime;
//endregion
    private HuanBaoItemActivity instances = null;
    private String[] shi_fou_str = new String[]{"否", "是"};//0 否 1 是

    private List<HuanBaoItemModel> typeModelListAdapter = new ArrayList<>();
    private HuanBaoModel carsInforModel;
    private String Login_name = "", huanbao_Line = "01", login_IDNumber = "1", login_username;//当前登录的检测员的名字,线号
    private String lichengshu, biansuxiang, jinqifangshi;//行驶里程数,变速箱,进气方式
    private String qudongfangshi, qigangshu, ranyouxingshi, paqiqiguan_shuliang,
            obd, hudongche, chunranyou, sanyuan_cuihuaqi, huoxingtan,
            ranyou_zhengfa, dpf, scr, doc, poc, qingdan_zhuangzhi;

    private String qudong_dianji_xinghao, chuneng_zhuangzhi_xinghao, dianchi_rongliang,
            qudong_dianji_gonglv, dianchi_dianya, sanyuan_xinghao, eding_gonglv,
            eding_zhuansu, dpf_xinghao, scr_xinghao, doc_xinghao, poc_xinghao,
            qingdan_yizhi, qingdan_bianhao, paifang_jieduan;


    int recLen = 0;
    Handler handler = new Handler();
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            recLen++;
            if (recLen < 1600) {
                acHuanbaoItemTimeTime.setText("项目进行时间：" + recLen + "  秒");
            }
            handler.postDelayed(this, 1000);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_huan_bao_item);
        ButterKnife.bind(this);
        instances = this;
        setBackBtn();
        setTopTitle("环保项目检测");

        acHuanbaoItemCountupViewTest3.setTag("test1");
        long time1 = (long) 1000;
        acHuanbaoItemCountupViewTest3.start(time1);
//        acHuanbaoItemCountupViewTest3.setOnCountdownIntervalListener(1000, new CountupView.OnCountdownIntervalListener() {
//            @Override
//            public void onInterval(CountupView cv, long remainTime) {
//                UtilsLog.e("onInterval===remainTime===" + remainTime);
//            }
//        });
//        acHuanbaoItemCountupViewTest3.setOnCountdownEndListener(new CountupView.OnCountdownEndListener() {
//            @Override
//            public void onEnd(CountupView cv) {
//                cv.stop();
//                UtilsLog.e("onEnd===");
//            }
//        });
//        handler.postDelayed(runnable, 1000);

        carsInforModel = (HuanBaoModel) getIntent().getSerializableExtra
                ("CarDetailsActivity_CarsInforModel");
        Login_name = getIntent().getExtras().getString("login_w_name", "");
        login_IDNumber = getIntent().getExtras().getString("login_IDNumber", "");
        login_username = getIntent().getExtras().getString("login_username", "");
        UtilsLog.e("login_IDNumber===" + login_IDNumber);
        UtilsLog.e("Login_name===" + Login_name);
        huanbao_Line = getIntent().getExtras().getString("huanbao_Line", "01");

        huanbao_Line = String.format("%02d", Integer.parseInt(huanbao_Line));

        lichengshu = getIntent().getExtras().getString("lichengshu", "0");
        biansuxiang = getIntent().getExtras().getString("biansuxiang", "");
        jinqifangshi = getIntent().getExtras().getString("jinqifangshi", "");

        qudongfangshi = getIntent().getExtras().getString("qudongfangshi", "");
//        qigangshu = getIntent().getExtras().getString("qigangshu", "1");
        qigangshu = carsInforModel.getCylinder();
        ranyouxingshi = getIntent().getExtras().getString("ranyouxingshi", "");
        paqiqiguan_shuliang = getIntent().getExtras().getString("paqiqiguan_shuliang", "1");
        obd = getIntent().getExtras().getString("obd", "");
        hudongche = getIntent().getExtras().getString("hudongche", "");
        chunranyou = getIntent().getExtras().getString("chunranyou", "");
        sanyuan_cuihuaqi = getIntent().getExtras().getString("sanyuan_cuihuaqi", "");
        UtilsLog.e("sanyuan_cuihuaqi===" + sanyuan_cuihuaqi);
        huoxingtan = getIntent().getExtras().getString("huoxingtan", "");
        ranyou_zhengfa = getIntent().getExtras().getString("ranyou_zhengfa", "");
        dpf = getIntent().getExtras().getString("dpf", "");
        scr = getIntent().getExtras().getString("scr", "");
        doc = getIntent().getExtras().getString("doc", "");
        poc = getIntent().getExtras().getString("poc", "");
        qingdan_zhuangzhi = getIntent().getExtras().getString("qingdan_zhuangzhi", "");

        qudong_dianji_xinghao = getIntent().getExtras().getString("qudong_dianji_xinghao", "");
        chuneng_zhuangzhi_xinghao = getIntent().getExtras().getString("chuneng_zhuangzhi_xinghao", "");
        qudong_dianji_gonglv = getIntent().getExtras().getString("qudong_dianji_gonglv", "");
        dianchi_dianya = getIntent().getExtras().getString("dianchi_dianya", "");
        sanyuan_xinghao = getIntent().getExtras().getString("sanyuan_xinghao", "");
        eding_gonglv = getIntent().getExtras().getString("eding_gonglv", "0");
        eding_zhuansu = getIntent().getExtras().getString("eding_zhuansu", "0");
        dpf_xinghao = getIntent().getExtras().getString("dpf_xinghao", "");
        scr_xinghao = getIntent().getExtras().getString("scr_xinghao", "");
        doc_xinghao = getIntent().getExtras().getString("doc_xinghao", "");
        poc_xinghao = getIntent().getExtras().getString("poc_xinghao", "");
        qingdan_yizhi = getIntent().getExtras().getString("qingdan_yizhi", "0");
        qingdan_bianhao = getIntent().getExtras().getString("qingdan_bianhao", "");
        //paifang_jieduan = getIntent().getExtras().getString("paifang_jieduan", "");
        if (TextUtils.isEmpty(qingdan_yizhi) || qingdan_yizhi.equals("") ||
                qingdan_yizhi.equals(" ")) {
            qingdan_yizhi = "是";
        }

        dianchi_rongliang = carsInforModel.getBatteryCapacity();
        paifang_jieduan = carsInforModel.getApprovalValue();

        setRightTxt("完成", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                long ll=acHuanbaoItemCountupViewTest3.getRemainTime();
                UtilsLog.e("ll==========="+ll);
                if(ll>15000){
                    getDataReportData();
                    getDataHuanBao();
                }else{
                    Toast.makeText(instances, "时间不够15秒", Toast.LENGTH_LONG).show();
                }
            }
        });

//        if (carsInforModel.getOBD().equals("有")) {
//            acHuanH14.setText("是");
//            includeHuanH1.setText("是");
//            HUANBAO_ITEMS[10][1] = "1";//是否带有OBD
//            HUANBAO_ITEMS[17][1] = "1"; //点火开关ON，ODB故障指示器（mil灯）是否激活
//        } else {
//            acHuanH14.setText("否");
//            includeHuanH1.setText("否");
//            HUANBAO_ITEMS[10][1] = "0";//是否带有OBD
//            HUANBAO_ITEMS[17][1] = "0"; //点火开关ON，ODB故障指示器（mil灯）是否激活
//        }

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        acHuanbaoItemCountupViewTest3.stop();
    }

    void showDianKongBeng(int show) {
        //1:show  0:hide
        if (show == 1) {
            llAcHuanShifouDiankongbengTv.setVisibility(View.VISIBLE);
            llAcHuanShifouDiankongbeng.setVisibility(View.VISIBLE);
        } else {
            llAcHuanShifouDiankongbengTv.setVisibility(View.GONE);
            llAcHuanShifouDiankongbeng.setVisibility(View.GONE);
        }
    }

    @OnClick({R.id.ac_huan_h_16, R.id.ac_huan_h_21, R.id.ac_huan_h_18,
            R.id.ac_huan_tongfeng, R.id.ac_huan_shifou_ranyou_zhengfa_kongzhi_zhuangzhi,
            R.id.ac_huan_h_19, R.id.ac_huan_h_20, R.id.ac_huan_jin_paiqi,
            R.id.ac_huan_h_22, R.id.ac_huan_h_14, R.id.ac_huan_h_23,
            R.id.ac_huan_h_24, R.id.ac_huan_h_25, R.id.ac_huan_h_26,
            R.id.ac_huan_h_27, R.id.ac_huan_h_28, R.id.ac_huan_shifou_diankongbeng
            , R.id.include_huan_h_1, R.id.include_huan_h_2, R.id.include_huan_h_3,
            R.id.include_huan_h_10, R.id.include_huan_h_11, R.id.include_huan_h_12,
            R.id.include_huan_h_13, R.id.include_huan_h_15, R.id.include_huan_youxianggai})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ac_huan_h_16:
                // 车辆机械状况是否良好
                showHuanDialog(shi_fou_str, R.id.ac_huan_h_16);
                break;
            case R.id.ac_huan_h_21:
                // 排气污染控制装置是否齐全正常
                showHuanDialog(shi_fou_str, R.id.ac_huan_h_21);
                break;
            case R.id.ac_huan_h_18:
                // 是否烧机油或严重冒黑烟
                showHuanDialog(shi_fou_str, R.id.ac_huan_h_18);
                break;
            case R.id.ac_huan_tongfeng:
                //汽油车曲轴箱通风系统是否正常
                showHuanDialog(shi_fou_str, R.id.ac_huan_tongfeng);
                break;
            case R.id.ac_huan_shifou_ranyou_zhengfa_kongzhi_zhuangzhi:
                //是否有燃油蒸发控制装置
                showHuanDialog(shi_fou_str, R.id.ac_huan_shifou_ranyou_zhengfa_kongzhi_zhuangzhi);
                break;
            case R.id.ac_huan_h_19:
                // 车上仪表工作是否正常
                showHuanDialog(shi_fou_str, R.id.ac_huan_h_19);
                break;
            case R.id.ac_huan_h_20:
                // 有无影响安全或引起测试偏差的机械故障:
                showHuanDialog(shi_fou_str, R.id.ac_huan_h_20);
                break;
            case R.id.ac_huan_jin_paiqi:
                // 车辆进排气系统是否有任何泄露
                showHuanDialog(shi_fou_str, R.id.ac_huan_jin_paiqi);
                break;
            case R.id.ac_huan_h_22:
                // 发动机、变速箱、冷却系统有无明显液体渗漏
                showHuanDialog(shi_fou_str, R.id.ac_huan_h_22);
                break;
            case R.id.ac_huan_h_14:
                // 是否带有OBD系统
                showHuanDialog(shi_fou_str, R.id.ac_huan_h_14);
                break;
            case R.id.ac_huan_h_23:
                // 轮胎胎压是否正常
                showHuanDialog(shi_fou_str, R.id.ac_huan_h_23);
                break;
            case R.id.ac_huan_h_24:
                // 轮胎是否干燥清洁
                showHuanDialog(shi_fou_str, R.id.ac_huan_h_24);
                break;
            case R.id.ac_huan_h_25:
                // 是否关闭车上空调、暖风等附属设备
                showHuanDialog(shi_fou_str, R.id.ac_huan_h_25);
                break;
            case R.id.ac_huan_h_26:
                // 是否已经中断可能影响测试的ARS/ESP/EPC/自动制动等功能
                showHuanDialog(shi_fou_str, R.id.ac_huan_h_26);
                break;
            case R.id.ac_huan_h_27:
                // 车辆油箱和油品是否异常
                showHuanDialog(shi_fou_str, R.id.ac_huan_h_27);
                break;
            case R.id.ac_huan_h_28:
                // 是否适合工况法检测
                showHuanDialog(shi_fou_str, R.id.ac_huan_h_28);
                break;
            case R.id.ac_huan_shifou_diankongbeng:
                //发动机燃油系统是否采用电控泵
                showHuanDialog(shi_fou_str, R.id.ac_huan_shifou_diankongbeng);
                break;
            case R.id.include_huan_h_1:
                //点火开关ON，ODB故障指示器（mil灯）是否激活
                showHuanDialog(shi_fou_str, R.id.include_huan_h_1);
                break;
            case R.id.include_huan_h_2:
                //起动发动机后，仪表盘OBD故障指示器（mil灯）有无点亮报警
                showHuanDialog(shi_fou_str, R.id.include_huan_h_2);
                break;
            case R.id.include_huan_h_3:
                //OBD接口通讯是否正常
                showHuanDialog(shi_fou_str, R.id.include_huan_h_3);
                break;
            case R.id.include_huan_h_10:
                //号牌是否一致
                showHuanDialog(shi_fou_str, R.id.include_huan_h_10);
                break;
            case R.id.include_huan_h_11:
                //车架号是否一致
                showHuanDialog(shi_fou_str, R.id.include_huan_h_11);
                break;
            case R.id.include_huan_h_12:
                //发动机号是否一致
                showHuanDialog(shi_fou_str, R.id.include_huan_h_12);
                break;
            case R.id.include_huan_h_13:
                //品牌型号/车辆类型是否一致
                showHuanDialog(shi_fou_str, R.id.include_huan_h_13);
                break;
            case R.id.include_huan_h_15:
                //车辆水温是否正常
                showHuanDialog(shi_fou_str, R.id.include_huan_h_15);
                break;
            case R.id.include_huan_youxianggai:
                //车辆油箱盖是否正常使用
                showHuanDialog(shi_fou_str, R.id.include_huan_youxianggai);
                break;
        }
    }

    private void showHuanDialog(String[] str, final int id) {
        BottomMenu.show(this, str, new OnMenuItemClickListener() {
            @Override
            public void onClick(String text, int index) {
                //返回参数 text 即菜单名称，index 即菜单索引
                switch (id) {
                    case R.id.ac_huan_h_16:
                        // 车辆机械状况是否良好
                        acHuanH16.setText(text);
//                        HUANBAO_CODE_SELECTED[0] = String.valueOf(index);
                        HUANBAO_ITEMS[0][1] = String.valueOf(index);
                        break;
                    case R.id.ac_huan_h_21:
                        // 排气污染控制装置是否齐全正常
                        acHuanH21.setText(text);
//                        HUANBAO_CODE_SELECTED[1] = String.valueOf(index);
                        HUANBAO_ITEMS[1][1] = String.valueOf(index);
                        break;
                    case R.id.ac_huan_h_18:
                        // 是否烧机油或严重冒黑烟
                        acHuanH18.setText(text);
//                        HUANBAO_CODE_SELECTED[2] = String.valueOf(index);
                        HUANBAO_ITEMS[2][1] = String.valueOf(index);
                        break;
                    case R.id.ac_huan_shifou_diankongbeng:
                        //发动机燃油系统是否采用电控泵
                        acHuanShifouDiankongbeng.setText(text);
//                        HUANBAO_CODE_SELECTED[16] = String.valueOf(index);
                        HUANBAO_ITEMS[3][1] = String.valueOf(index);
                        break;
                    case R.id.ac_huan_tongfeng:
                        //汽油车曲轴箱通风系统是否正常
                        acHuanTongfeng.setText(text);
//                        HUANBAO_CODE_SELECTED[3] = String.valueOf(index);
                        HUANBAO_ITEMS[4][1] = String.valueOf(index);
                        break;
                    case R.id.ac_huan_shifou_ranyou_zhengfa_kongzhi_zhuangzhi:
                        //是否有燃油蒸发控制装置
                        acHuanShifouRanyouZhengfaKongzhiZhuangzhi.setText(text);
//                        HUANBAO_CODE_SELECTED[4] = String.valueOf(index);
                        HUANBAO_ITEMS[5][1] = String.valueOf(index);
                        break;
                    case R.id.ac_huan_h_19:
                        // 车上仪表工作是否正常
                        acHuanH19.setText(text);
//                        HUANBAO_CODE_SELECTED[5] = String.valueOf(index);
                        HUANBAO_ITEMS[6][1] = String.valueOf(index);
                        break;
                    case R.id.ac_huan_h_20:
                        // 有无影响安全或引起测试偏差的机械故障:
                        acHuanH20.setText(text);
//                        HUANBAO_CODE_SELECTED[6] = String.valueOf(index);
                        HUANBAO_ITEMS[7][1] = String.valueOf(index);
                        break;
                    case R.id.ac_huan_jin_paiqi:
                        // 车辆进排气系统是否有任何泄露
                        acHuanJinPaiqi.setText(text);
//                        HUANBAO_CODE_SELECTED[7] = String.valueOf(index);
                        HUANBAO_ITEMS[8][1] = String.valueOf(index);
                        break;
                    case R.id.ac_huan_h_22:
                        // 发动机、变速箱、冷却系统有无明显液体渗漏
                        acHuanH22.setText(text);
//                        HUANBAO_CODE_SELECTED[8] = String.valueOf(index);
                        HUANBAO_ITEMS[9][1] = String.valueOf(index);
                        break;
                    case R.id.ac_huan_h_14:
                        // 是否带有OBD系统
                        acHuanH14.setText(text);
//                        HUANBAO_CODE_SELECTED[9] = String.valueOf(index);
                        HUANBAO_ITEMS[10][1] = String.valueOf(index);
                        UtilsLog.e("是否带有OBD系统==" + text + "=====" + index);
                        break;
                    case R.id.ac_huan_h_23:
                        // 轮胎胎压是否正常
                        acHuanH23.setText(text);
//                        HUANBAO_CODE_SELECTED[10] = String.valueOf(index);
                        HUANBAO_ITEMS[11][1] = String.valueOf(index);
                        break;
                    case R.id.ac_huan_h_24:
                        // 轮胎是否干燥清洁
                        acHuanH24.setText(text);
//                        HUANBAO_CODE_SELECTED[11] = String.valueOf(index);
                        HUANBAO_ITEMS[12][1] = String.valueOf(index);
                        break;
                    case R.id.ac_huan_h_25:
                        // 是否关闭车上空调、暖风等附属设备
                        acHuanH25.setText(text);
//                        HUANBAO_CODE_SELECTED[12] = String.valueOf(index);
                        HUANBAO_ITEMS[13][1] = String.valueOf(index);
                        break;
                    case R.id.ac_huan_h_26:
                        // 是否已经中断可能影响测试的ARS/ESP/EPC/自动制动等功能
                        acHuanH26.setText(text);
//                        HUANBAO_CODE_SELECTED[13] = String.valueOf(index);
                        HUANBAO_ITEMS[14][1] = String.valueOf(index);
                        if (acHuanH26.getText().toString().equals("否")){
                            Toast.makeText(instances,"未中断车辆上可能影响测试正常进行的功能,如 ARS、ESP、EPC牵引力控制或自动制动系统等，不应上线检测", Toast.LENGTH_LONG).show();
                        }
                        break;
                    case R.id.ac_huan_h_27:
                        // 车辆油箱和油品是否异常
                        acHuanH27.setText(text);
//                        HUANBAO_CODE_SELECTED[14] = String.valueOf(index);
                        HUANBAO_ITEMS[15][1] = String.valueOf(index);
                        break;
                    case R.id.ac_huan_h_28:
                        // 是否适合工况法检测
                        acHuanH28.setText(text);
//                        HUANBAO_CODE_SELECTED[15] = String.valueOf(index);
                        UtilsLog.e("是否适合工况法检测====" + text + "===" + index);
                        HUANBAO_ITEMS[16][1] = String.valueOf(index);
                        break;
                    case R.id.include_huan_h_1:
                        //点火开关ON，ODB故障指示器（mil灯）是否激活
                        includeHuanH1.setText(text);
//                        HUANBAO_CODE_SELECTED[17] = String.valueOf(index);
                        HUANBAO_ITEMS[17][1] = String.valueOf(index);
                        UtilsLog.e("点火开关ON，ODB故障指示器（mil灯）是否激活==" + text + "===" + index);
                        break;
                    case R.id.include_huan_h_2:
                        //起动发动机后，仪表盘OBD故障指示器（mil灯）有无点亮报警
                        includeHuanH2.setText(text);
//                        HUANBAO_CODE_SELECTED[18] = String.valueOf(index);
                        HUANBAO_ITEMS[18][1] = String.valueOf(index);
                        break;
                    case R.id.include_huan_h_3:
                        //OBD接口通讯是否正常
                        includeHuanH3.setText(text);
//                        HUANBAO_CODE_SELECTED[19] = String.valueOf(index);
                        HUANBAO_ITEMS[19][1] = String.valueOf(index);
                        break;
                    case R.id.include_huan_h_10:
                        //号牌是否一致
                        includeHuanH10.setText(text);
//                        HUANBAO_CODE_SELECTED[20] = String.valueOf(index);
                        HUANBAO_ITEMS[20][1] = String.valueOf(index);
                        break;
                    case R.id.include_huan_h_11:
                        //车架号是否一致
                        includeHuanH11.setText(text);
//                        HUANBAO_CODE_SELECTED[21] = String.valueOf(index);
                        HUANBAO_ITEMS[21][1] = String.valueOf(index);
                        break;
                    case R.id.include_huan_h_12:
                        //发动机号是否一致
                        includeHuanH12.setText(text);
//                        HUANBAO_CODE_SELECTED[22] = String.valueOf(index);
                        HUANBAO_ITEMS[22][1] = String.valueOf(index);
                        break;
                    case R.id.include_huan_h_13:
                        //品牌型号/车辆类型是否一致
                        includeHuanH13.setText(text);
//                        HUANBAO_CODE_SELECTED[23] = String.valueOf(index);
                        HUANBAO_ITEMS[23][1] = String.valueOf(index);
                        break;
                    case R.id.include_huan_h_15:
                        //车辆水温是否正常
                        includeHuanH15.setText(text);
//                        HUANBAO_CODE_SELECTED[24] = String.valueOf(index);
                        HUANBAO_ITEMS[24][1] = String.valueOf(index);
                        break;
                    case R.id.include_huan_youxianggai:
                        //车辆油箱盖是否正常使用
                        includeHuanYouxianggai.setText(text);
//                        HUANBAO_CODE_SELECTED[25] = String.valueOf(index);
                        HUANBAO_ITEMS[25][1] = String.valueOf(index);
                        break;

                }
            }
        }).setMenuTextInfo(new TextInfo().setBold(true).setFontColor(Color.BLACK).setGravity(Gravity.CENTER));
    }

    //上传数据
    private void getDataReportData() {
        typeModelListAdapter = new ArrayList<>();
        HuanBaoItemModel typeModel = null;
        for (int i = 1; i < 27; i++) {
            typeModel = new HuanBaoItemModel();
            UtilsLog.e("Name====HUANBAO_ITEMS[" + (i - 1) + "][1]==" + HUANBAO_ITEMS[i - 1][1]);
            UtilsLog.e("type====HUANBAO_ITEMS[" + (i - 1) + "][0]==" + HUANBAO_ITEMS[i - 1][0]);
            if (i == 11) {
                //是否有OBD
                typeModel.setName(changIntShiFou(acHuanH14.getText().toString().trim()));
            } else if (i == 15) {
                //是否已经中断可能影响测试的ARS/ESP/EPC/自动制动等功能
                typeModel.setName(changIntShiFou(acHuanH26.getText().toString().trim()));
            } else if (i == 17) {
                //是否适合工况法检测
                typeModel.setName(changIntShiFou(acHuanH28.getText().toString().trim()));
            } else if (i == 18) {
                //点火开关ON，ODB故障指示器（mil灯）是否激活:
                typeModel.setName(changIntShiFou(includeHuanH1.getText().toString().trim()));
            } else if (i == 19) {
                //起动发动机后，仪表盘OBD故障指示器（mil灯）有无点亮报警:
                typeModel.setName(changIntShiFou(includeHuanH2.getText().toString().trim()));
            } else {
                typeModel.setName(HUANBAO_ITEMS[i - 1][1]);
            }
            typeModel.setCode(String.valueOf(i));
            typeModel.setSelected(0);
            typeModel.setType(HUANBAO_ITEMS[i - 1][0]);
            typeModelListAdapter.add(typeModel);
        }
        UtilsLog.e("getDataReportData---url==" + SharedPreferencesUtils.getHuanBaoIP(instances) + REPORTED_DATA);
//        myjson = reportedJsonStr();
        List<ResultModel> resultModelList = new ArrayList<>();
        ResultModel model = null;
        for (int i = 0; i < typeModelListAdapter.size(); i++) {
            model = new ResultModel();
//            model.setCode(Integer.parseInt(typeModelListAdapter.get(i).getCode()));
            model.setCode(typeModelListAdapter.get(i).getCode());
            model.setDataType("F1_H");
            model.setDetection_ID(carsInforModel.getID());
            model.setTimes(carsInforModel.getTimes());
            model.setGUID(carsInforModel.getGUID());
            UtilsLog.e("typeModelListAdapter==" + i + "====" + typeModelListAdapter.get(i).getName() + "::" + typeModelListAdapter.get(i).getCode());
            if (typeModelListAdapter.get(i).getName().equals("1")) {
                model.setVerdict("是");
            } else {
                model.setVerdict("否");
            }
            resultModelList.add(model);
        }
        Gson gson = new Gson();
        String jsonStr = gson.toJson(resultModelList);
        String logStr = "\n" + "外检上传自己后台数据--json---" +
                "\n" + "jsonStr::" + jsonStr + "\n" +
                SharedPreferencesUtils.getIP(instances) + REPORTED_DATA;
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());

        String logStr22 = "\n" + "外检上传自己后台数据--typeModelListAdapter---" +
                "\n" + "typeModelListAdapter::" + gson.toJson(typeModelListAdapter) + "\n";
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr22.getBytes());

        UtilsLog.e("getDataReportData-typeModelListAdapter=" + gson.toJson(typeModelListAdapter));
        UtilsLog.e("getDataReportData-result=myjson=" + jsonStr);
        OkGo.<String>post(SharedPreferencesUtils.getIP(instances) + REPORTED_DATA).tag(instances)
                .upJson(jsonStr)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        UtilsLog.e("getDataReportData-result==" + result);
                        String logStr = "\n" + "外检上传自己后台数据--请求成功" +
                                "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
                        if ("\"ok\"".equals(result)) {
//                            updateCarStatusInfor_anjian();
//                            Toast.makeText(instances, "上报数据成功", Toast.LENGTH_LONG).show();
//                            instances.finish();
                        } else {
//                            showDialog("上传后台数据失败，请重试，如果还未成功请联系管理员");
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("getDataReportData-onError==" + response.body());
                        UtilsLog.e("getDataReportData-onError==" + response.getException());
                        String logStr = "\n" + "外检上传自己后台数据-onError-失败" +
                                "\n" + "\n" + "result::" + response.body();
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
//                        Toast.makeText(instances, getResources().getString(R.string.services_error), Toast
//                                .LENGTH_LONG).show();
//                        showDialog("上传数据失败，请重试，如果还未成功请联系管理员");
                    }
                });
    }

    AlertDialog.Builder builder = null;

    private void showDialog(String content) {
        AlertDialog.Builder builder = new AlertDialog.Builder
                (instances);
        builder.setTitle("提示");
        builder.setMessage(content);
//        builder.setNegativeButton("取消", null);
        builder.setPositiveButton("确定", null);
        builder.show();
    }

    //将汉字“是否”转成数字命名1，0
    private String changIntShiFou(String shifou) {
        String result = "0";
        if (TextUtils.isEmpty(shifou)) {
            return "0";
        }
        if ("是".equals(shifou)) {
            result = "1";
        } else if ("否".equals(shifou)) {
            result = "0";
        }
        return result;
    }

    // 环保数据上传
    private void getDataHuanBao() {
        HuanBaoDataModel model = new HuanBaoDataModel();
//        model.setSN(carsInforModel.getSN());
        model.setSN(carsInforModel.getPlatformSN());
        model.setStationNO(SharedPreferencesUtils.getUserToken(instances));
        model.setLine(huanbao_Line);
        model.setTimes(carsInforModel.getTimes());

        if (carsInforModel.getDetectionCategory().equals("00")) {
            model.setDetectionCategory("2");
        } else {
            model.setDetectionCategory("1");
        }

        if (!TextUtils.isEmpty(Login_name)) {
            model.setAppearanceName(Login_name);
        }
        if (!TextUtils.isEmpty(login_IDNumber)) {
            model.setAppearanceID(login_IDNumber);
        }

        model.setAppearanceVerdict("1");
        model.setCarNO(carsInforModel.getPlateRegion() +
                carsInforModel.getPlateNO()
                + carsInforModel.getPlateExtra());
//        model.setCarNO(carsInforModel.getPlateRegion() +
//                carsInforModel.getPlateNO());
        model.setPlateType(carsInforModel.getPlateType());
        model.setPlateColor(carsInforModel.getPlateColor());
        model.setVIN(carsInforModel.getVIN());
        model.setVehicleType(carsInforModel.getType());
        model.setFuelType(carsInforModel.getFuelType());
        model.setDetectionDate(carsInforModel.getDetectDate());
        model.setStartTime(BaseApplication.huanbao_ItemStart_time);
        model.setFinishTime(DateUtil.currentTime2());
//        model.setTravelMiles(!lichengshu.equals("0")?lichengshu:"0");
//        model.setTravelMiles(carsInforModel.getOdometer());
        model.setTravelMiles(!lichengshu.equals("0")?lichengshu:carsInforModel.getOdometer());

//        if (carsInforModel.getOBD().equals("有")) {

        if (acHuanH14.getText().toString().trim().contains("有")) {
            if ("是".equals(includeHuanH1.getText().toString().trim())) {
                model.setOBDMil1("1");
            } else {
                model.setOBDMil1("0");
            }
            if ("是".equals(includeHuanH2.getText().toString().trim())) {
                model.setOBDMil2("1");
            } else {
                model.setOBDMil2("0");
            }
            if ("是".equals(includeHuanH3.getText().toString().trim())) {
                model.setOBDCommunication("1");
            } else {
                model.setOBDCommunication("0");
            }
        } else {
            model.setOBDMil1(" ");
            model.setOBDMil2(" ");
            model.setOBDCommunication(" ");
        }

        if ("手动".equals(biansuxiang)) {
            model.setTransmissionType("1");
        } else {
            model.setTransmissionType("2");
        }

        //自然进气  1
        if ("0".equals(carsInforModel.getAirAdmission())) {
            model.setAirMode("1");
        } else {
            model.setAirMode("2");
        }
        if ("前驱".equals(qudongfangshi)) {
            model.setDrivingMode("1");
        } else if ("后驱".equals(qudongfangshi)) {
            model.setDrivingMode("2");
        } else if ("全时四驱".contains(qudongfangshi)) {
            model.setDrivingMode("3");
        } else {
            model.setDrivingMode("4");
        }
        model.setCylinderNumber(qigangshu);

        // 化油器、化油器改造----11，
        // 闭环电喷、开环电喷、直喷----12，
        // 单体泵、直列泵、机械泵----21，
        // 高压共轨----22，
        // 泵喷嘴---23
        if (carsInforModel.getFuelType().equalsIgnoreCase("B")) {
            if (ranyouxingshi.contains("单体泵") || ranyouxingshi.contains("直列泵") || ranyouxingshi.contains("机械泵")) {
                model.setFuleWay("21");
            } else if (ranyouxingshi.contains("高压共轨")) {
                model.setFuleWay("22");
            } else {
                model.setFuleWay("23");
            }
        } else {
            if (ranyouxingshi.contains("化油器")) {
                model.setFuleWay("11");
            } else if (ranyouxingshi.contains("电喷") || ranyouxingshi.contains("直喷")) {
                model.setFuleWay("12");
            }
        }
//        model.setFuleWay(carsInforModel.getFuelType());
//        model.setFuelway(carsInforModel.getFuelSupply());

        model.setPipeNumber(paqiqiguan_shuliang.equals("0") ? "1" : paqiqiguan_shuliang);
        model.setIsOBD(changIntShiFou(obd));
        model.setMachineState(changIntShiFou(acHuanH16.getText().toString().trim()));
        model.setPollutionControl(changIntShiFou(acHuanH21.getText().toString().trim()));
        model.setBurnOil(changIntShiFou(acHuanH18.getText().toString().trim()));
        model.setDeviceState(changIntShiFou(acHuanH19.getText().toString().trim()));
        model.setMachineFailure(changIntShiFou(acHuanH20.getText().toString().trim()));
        model.setAirInOut(changIntShiFou(acHuanJinPaiqi.getText().toString().trim()));
        model.setLiquidLeake(changIntShiFou(acHuanH22.getText().toString().trim()));
        model.setTirePressure(changIntShiFou(acHuanH23.getText().toString().trim()));
        model.setTireClean(changIntShiFou(acHuanH24.getText().toString().trim()));
        model.setIsCloseAirConditioner(changIntShiFou(acHuanH25.getText().toString().trim()));
        model.setIsCloseESP(changIntShiFou(acHuanH26.getText().toString().trim()));
        model.setFuelTankState(changIntShiFou(acHuanH27.getText().toString().trim()));
        model.setIsASM(changIntShiFou(acHuanH28.getText().toString().trim()));
        model.setHybridCar(changIntShiFou(hudongche));
        model.setOnlyFuelMode(changIntShiFou(chunranyou));
        model.setDriveMotorModel(qudong_dianji_xinghao);
        model.setEnergyStorageModel(chuneng_zhuangzhi_xinghao);
        model.setBatteryCapacity(dianchi_rongliang);
        model.setDriveMotorPower(qudong_dianji_gonglv);
        model.setBatteryVoltage(dianchi_dianya);
//        model.setThreeWayCatalytic(changIntShiFou(sanyuan_cuihuaqi));
        model.setThreeWayCatalytic(carsInforModel.getTWC());
        model.setThreeWayCatalyticModel(sanyuan_xinghao);
        model.setFuelEvaporation(changIntShiFou(acHuanShifouRanyouZhengfaKongzhiZhuangzhi.getText().toString().trim()));
        model.setCrankcase(changIntShiFou(acHuanTongfeng.getText().toString().trim()));
        model.setActivatedCarbonTank(changIntShiFou(huoxingtan));
        model.setFuelEvaporationNormal(changIntShiFou(ranyou_zhengfa));
        model.setFuelTankCap(changIntShiFou(includeHuanYouxianggai.getText().toString().trim()));
//        model.setRatePower(eding_gonglv.equals("")?"0":eding_gonglv  carsInforModel.getrat);
//        model.setRateSpeed(eding_zhuansu.equals("")?"0":eding_zhuansu);
        model.setRatePower(carsInforModel.getPower());
        model.setRateSpeed(carsInforModel.getMotoRate());
        model.setIsDOC(changIntShiFou(doc));
        model.setDOCModel(doc_xinghao);
        model.setIsDPF(changIntShiFou(dpf));
        model.setDPFModel(dpf_xinghao);
        model.setIsSCR(changIntShiFou(scr));
        model.setSCRModel(scr_xinghao);
        model.setIsPOC(changIntShiFou(poc));
        model.setPOCModel(poc_xinghao);
        model.setElectricPump(changIntShiFou(acHuanShifouDiankongbeng.getText().toString().trim()));
        model.setOnBoardDevice(changIntShiFou(qingdan_zhuangzhi));
        model.setOnBoardNO(qingdan_bianhao);
//        model.setOnBoardPublish(qingdan_yizhi);
        model.setOnBoardPublish(changIntShiFou(qingdan_yizhi));


//        if (paifang_jieduan.contains("1")) {
//            model.setEmissionStage("1");
//        } else if (paifang_jieduan.contains("2")) {
//            model.setEmissionStage("2");
//        } else if (paifang_jieduan.contains("3")) {
//            model.setEmissionStage("3");
//        } else if (paifang_jieduan.contains("4")) {
//            model.setEmissionStage("4");
//        } else if (paifang_jieduan.contains("5")) {
//            model.setEmissionStage("5");
//        } else if (paifang_jieduan.contains("6")) {
//            model.setEmissionStage("6a");
//        } else if (paifang_jieduan.contains("D")) {
//            model.setEmissionStage("D");
//        } else {
//            model.setEmissionStage("6b");
//        }
        model.setEmissionStage(paifang_jieduan);
        Gson gson = new Gson();
        String jsonStr = gson.toJson(model);

        String logStr = "\n" + "环保---上传数据--请求成功" +
                "\n" + "jsonStr::" + jsonStr + ":::" + "\n"
                + "ip:::" + SharedPreferencesUtils.getHuanBaoIP(instances) + HUANBAO_DATA;
        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());

        UtilsLog.e("getDataHuanBao-ip=" + SharedPreferencesUtils.getHuanBaoIP(instances) + HUANBAO_DATA);
        UtilsLog.e("getDataHuanBao-result=myjson=" + jsonStr);
        OkGo.<String>post(SharedPreferencesUtils.getHuanBaoIP(instances) + HUANBAO_DATA).tag(instances)
                .upJson(jsonStr)
                .execute(new StringCallback() {
                    @Override
                    public void onStart(Request<String, ? extends Request> request) {
                        super.onStart(request);
//                        CommonUtils.showLoadingDialog(instances, "加载中...");
                    }

                    @Override
                    public void onSuccess(Response<String> response) {
                        String result = response.body();
                        UtilsLog.e("getDataHuanBao-result==" + result);
                        String logStr = "\n" + "环保--外检上传数据--请求成功" +
                                "\n" + "result::" + response.body() + "\n" +
                                SharedPreferencesUtils.getHuanBaoIP(instances) + HUANBAO_DATA;
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
                        if ("\"ok\"".equals(result)) {
//                            updateCarStatusInfor_anjian();
                            Toast.makeText(instances, "上报数据成功", Toast.LENGTH_LONG).show();
                            instances.finish();
                        } else {
                            showDialog("上传数据失败，请重试，如果还未成功请联系管理员");
                        }
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        UtilsLog.e("getDataHuanBao-onError==" + response.body());
                        UtilsLog.e("getDataHuanBao-onError==" + response.getException());
                        String logStr = "\n" + "环保--外检上传自己后台数据-onError-失败" +
                                "\n" + "\n" + "result::" + response.body() + "\n" +
                                SharedPreferencesUtils.getHuanBaoIP(instances) + HUANBAO_DATA;
                        PDALogUtils.createLogFile(BaseApplication.JIANCE_MODE, logStr.getBytes());
                        CommonUtils.hideLoadingDialog(instances);
                        showDialog("上传数据失败，请重试，如果还未成功请联系管理员");
                    }
                });
    }


}
